package com.hr.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.hr.model.PubinfoModel;
import com.hr.model.UserModel;
import com.hr.service.PubinfoService;
/**
 * 公告管理
 * @author fazhen.zheng
 *
 */
@Controller
public class PubinfoController {
	@Autowired
	private PubinfoService pubinfoService;
	@RequestMapping("/pubinfo/pubinfoList")
	public ModelAndView findAll(){
		List<PubinfoModel> PubinfoModels = pubinfoService.findAll();
		ModelAndView mv = new ModelAndView("pubinfo/pubinfoList");
		mv.addObject("PubinfoModels", PubinfoModels);
		return mv;
	}
	@RequestMapping("/pubinfo/editPubinfo")
	public ModelAndView prepareEdit(String id){
		ModelAndView mv = new ModelAndView("pubinfo/editPubinfo");
		return mv;
	}
	@RequestMapping("/pubinfo/addPubinfo")
	public ModelAndView addPubinfo(PubinfoModel pubinfoModel,HttpServletRequest request){
		UserModel user = (UserModel) request.getSession().getAttribute("user");
		pubinfoService.addPubinfo(pubinfoModel,user);
		return findAll();
	}
	@RequestMapping("/pubinfo/delete")
	public ModelAndView deletePubinfo(String id){
		pubinfoService.delete(id);
		return findAll();
	}
	@RequestMapping("/pubinfo/pubinfo")
	public ModelAndView pubinfo(String id){
		PubinfoModel pubinfoModel = pubinfoService.findById(id);
		ModelAndView mv = new ModelAndView("pubinfo/pubinfo");
		mv.addObject("Pubinfo", pubinfoModel);
		return mv;
	}
}
